# sngeditor.py
# Copyright (C) 2007 Sergio Perez Camacho - BRUE
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



import pygame
from pygame.locals import *
import sys

pygame.mixer.init()

pygame.mixer.music.load(sys.argv[1])


l1 = []
l2 = []
l3 = []
l4 = []
l5 = []

pygame.init()
screen = pygame.display.set_mode((320,240), HWSURFACE|DOUBLEBUF)    
    
surf = pygame.Surface(screen.get_size())
screen.blit(surf, (0,0))
pygame.display.flip()

pygame.mixer.music.play()


while float(pygame.mixer.music.get_pos()) > 0:
    for event in pygame.event.get():
        if (event.type == KEYDOWN):
            if (event.key==K_q):
                print "added 1"
                l1.append(pygame.mixer.music.get_pos())
            if (event.key==K_w):
                print "added 2"
                l2.append(pygame.mixer.music.get_pos())
            if (event.key==K_e):
                print "added 3"
                l3.append(pygame.mixer.music.get_pos())
            if (event.key==K_r):
                print "added 4"
                l4.append(pygame.mixer.music.get_pos())
            if (event.key==K_t):
                print "added 5"
                l5.append(pygame.mixer.music.get_pos())

f = open(sys.argv[1][:-4]+".sng","w")
f.write("[BPM]\n")
f.write("140\n")
f.write("[1]\n")
for l in l1:
    value = str(l) + "\n"
    f.write(value)
f.write("[2]\n")
for l in l2:
    value = str(l) + "\n"
    f.write(value)
f.write("[3]\n")
for l in l3:
    value = str(l) + "\n"
    f.write(value)
f.write("[4]\n")
for l in l4:
    value = str(l) + "\n"
    f.write(value)
f.write("[5]\n")
for l in l5:
    value = str(l) + "\n"
    f.write(value)
f.close()
